package com.sixth.controller;

import com.sixth.bean.MarketAd;
import com.sixth.bean.bo.AdvBeanBO;
import com.sixth.bean.bo.AdvPageInfo;
import com.sixth.bean.common.BaseRespVo;
import com.sixth.bean.vo.BaseListVO;
import com.sixth.constant.Constant;
import com.sixth.service.AdvService;
import org.apache.shiro.authz.annotation.Logical;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("admin/ad")
public class AdvController {

    @Autowired
    AdvService advService;

    /**
     * @Author Chen
     * @Date 2022-09-06  23-06-42
     * @param
     * @return {@link null }
     * @description 分页查询广告表中内容
     */
    @RequiresPermissions(value = {"admin:ad:list"},logical = Logical.OR)
    @GetMapping("list")
    public BaseRespVo advList(AdvPageInfo pageInfo){

        BaseListVO<MarketAd> advInfoVO = advService.getAdvList(pageInfo);

        return BaseRespVo.ok(advInfoVO);
    }

    /**
     * @Author Chen
     * @Date 2022-09-07  14-20-08
     * @param
     * @return {@link null }
     * @description 用户删除一条广告
     */
    @RequiresPermissions(value = {"admin:ad:delete"},logical = Logical.OR)
    @PostMapping("delete")
    public BaseRespVo deleteAdv(@RequestBody AdvBeanBO advBeanBO){

        int delCode = advService.deleteAdv(advBeanBO);

        if (delCode == Constant.OK){
            return BaseRespVo.ok("删除成功",0);
        }

        return BaseRespVo.invalidParameter("删除失败");
    }

    @PostMapping("create")
    public BaseRespVo adminAdCreate(@RequestBody MarketAd marketAd) {
        MarketAd res = advService.adminAdCreate(marketAd);
        return BaseRespVo.ok(res);
    }

    @GetMapping("read")
    public BaseRespVo adminAdRead() {
        return BaseRespVo.ok();
    }

    @PostMapping("update")
    public BaseRespVo adminAdUpdate(@RequestBody MarketAd marketAd) {
        MarketAd res = advService.adminAdUpdate(marketAd);
        return BaseRespVo.ok(res);
    }
}
